package com.efast.dmom.mgmt.controller.mes;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.entity.mes.PmSerialnumber;
import com.efast.dmom.mgmt.entity.mes.PrBasLoadingList;
import com.efast.dmom.mgmt.service.mes.PrBasLoadingListService;

@Controller
@RequestMapping("/PrintLoading")
public class PrBasLoadingListController {
	@Autowired
	private PrBasLoadingListService  loadingList;
	@RequestMapping(value="/printLoadingList")
	public @ResponseBody ResultBean printLoadingList(@RequestBody  PrBasLoadingList enti) throws Exception {
//		ResultBean result=new ResultBean(true,"'");
		ResultBean resultBean;
		if(enti.getPrintStatus()) {
			enti.setPrintType("AL_TCFNS");
			resultBean = loadingList.printLoadingList(enti);
		}else {
			resultBean = loadingList.printLoadingList(enti);
		}
			
		return resultBean;				
	}
	//打印驾驶室装车单
	@RequestMapping(value="/printCabList")
	public @ResponseBody ResultBean printCabList(@RequestBody  PrBasLoadingList enti) throws Exception {
//		ResultBean result=new ResultBean(true,"'");
		ResultBean resultBean;
		if(enti.getPrintStatus()) {
			enti.setPrintType("AL_CAB");
			resultBean = loadingList.printCabList(enti);
		}else {
			resultBean = loadingList.printCabList(enti);
		}
			
		return resultBean;
		
		
	}
//根据vin获取车型和颜色
	@RequestMapping(value="/modelColor")
	public @ResponseBody ResultBean getVehicleModelColor(@RequestBody  PmSerialnumber enti){
		ResultBean result  = new ResultBean(true,"'");
		String vin=enti.getVin();
		ResultBean resultModelColor =loadingList.getVehicleModelColor(vin);
		if(resultModelColor.success) {
			Map<?, ?> map = (Map<?, ?>)  resultModelColor.object;
			result.setSuccess(true);
			result.setObject(map);
			return result;
		}else {
			result.setSuccess(false);
			result.setMessage(resultModelColor.message);
			return result;
		}	
		
	}
	//装车单另存为
	@RequestMapping(value="/copyLoadList")
	public @ResponseBody ResultBean copyLoadList(@RequestBody  Map<String, Object> map) {
		ResultBean resultBean = loadingList.copyLoadList(map);
		return resultBean;
			
	}
	//新增装车单值
	@RequestMapping(value="/addLoadListHead")
	public @ResponseBody ResultBean addLoadListHead(@RequestBody PrBasLoadingList enti) {
		 ResultBean resultBean = loadingList.addLoadListHead(enti);
		return resultBean;
			
	}
	//新增装车单值
	@RequestMapping(value="/addLoadList/{id}")
	public @ResponseBody ResultBean addLoadList(@RequestBody List<PrBasLoadingList> list,@PathVariable Integer id) {
		 ResultBean resultBean = loadingList.addLoadingList(list,id);
		return resultBean;
			
	}
	//修改装车单值
	@RequestMapping(value="/updateLoadList")
	public @ResponseBody ResultBean updateLoadList(@RequestBody PrBasLoadingList enti) {
		 ResultBean resultBean = loadingList.updateLoadingList(enti);
		return resultBean;
			
	}
	
	//新增装车单值
	@RequestMapping(value="/deleteLoadListHead")
	public @ResponseBody ResultBean deleteLoadListHead(@RequestBody PrBasLoadingList enti) {
		ResultBean result=new ResultBean(true,"'");
        loadingList.deleteLoadingListHead(enti);
		return result;
			
	}
	//获取零件下拉选
	@RequestMapping(value="/getPartInfo")
	public @ResponseBody ResultBean getPartInfo(@RequestBody PrBasLoadingList enti) {
		ResultBean result=new ResultBean(true,"'");	
	    List<PrBasLoadingList> partInfo = loadingList.getPartInfo(enti);
	    result.setObject(partInfo);
		return result;
			
	}
	// 流程卡打印
	@RequestMapping(value = "/loadingListView")
	public @ResponseBody ResultBean printFlowCard(HttpServletRequest request, HttpServletResponse response,PrBasLoadingList enti) {	
		ResultBean result = new ResultBean(true, "'");
		loadingList.loadingListPreView(enti,response);
		return result;
	}
}
